package ui;

import services.SupplierServicempl;
import vo.Custom;
import vo.Supplier;

import java.util.List;
import java.util.Scanner;

public class SupplierLogin {
    static SupplierServicempl supplierServicempl=new SupplierServicempl();
   static Scanner scanner=new Scanner(System.in);
    public static void Login(){ //供应商表页面
        System.out.println("1,添加数据");
        System.out.println("2,删除数据");
        System.out.println("3,修改数据");
        System.out.println("4,查询数据");
        System.out.println("5,查询所有数据");
        System.out.println("0,返回上一级");
        System.out.println("请输入你的选择");
        int fuctionNumbre=scanner.nextInt();
        switch (fuctionNumbre){
            case 1:
                if(add()){
                    System.out.println("添加成功");
                }else {
                    System.out.println("添加失败");
                }
            case 2:
                if(delet()){
                    System.out.println("删除完成");
                }else {
                    System.out.println("删除失败");
                }
            case 3:
                if(modify()){
                    System.out.println("修改完成");
                }else {
                    System.out.println("修改失败");
                }
            case 4:
                Supplier supplier =getcustombyid();
                System.out.println(supplier);
                break;
            case 5:
                List<Supplier> list=getall();
                for(Supplier supplier1:list){
                    System.out.println(supplier1);
                }
                break;
            case 0:
                System.out.println("返回");
        }

    }

    private static boolean add() {
        System.out.println("请输入供应商姓名:");
        String name=scanner.nextLine();
        System.out.println("请输入供应商电话:");
        String snumber=scanner.nextLine();
        System.out.println("请输入供应家具的编号");
        int id=scanner.nextInt();
        System.out.println("请输入供应的数量");
        int count=scanner.nextInt();
        Supplier supplier=new Supplier(name,snumber,id,count);
        return supplierServicempl.add(supplier);
    }

    private static boolean delet() {
        System.out.println("请输入供应商姓名:");
        String name=scanner.nextLine();
        System.out.println("请输入供应商电话:");
        String snumber=scanner.nextLine();
        System.out.println("请输入供应家具的编号");
        int id=scanner.nextInt();
        System.out.println("请输入供应的数量");
        int count=scanner.nextInt();
        Supplier supplier=new Supplier(name,snumber,id,count);
         return supplierServicempl.delete(supplier);
    }

    private static boolean modify() {
        System.out.println("请输入供应商姓名:");
        String name=scanner.nextLine();
        Supplier supplier=new Supplier(name);
        return supplierServicempl.modify(supplier);
    }

    private static Supplier getcustombyid() {
        System.out.println("请输入供应商姓名:");
        String name=scanner.nextLine();
        return supplierServicempl.getcustombyid(name);
    }

    private static List<Supplier> getall() {
        return supplierServicempl.getall();
    }
}
